home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DOUBLEDE / MENUS.C < prev    next >
C/C++ Source or Header  |  1988-07-27  |  5KB  |  197 lines

  1. #include "shell.h"
  2.  
  3. /*====================================================================
  4.  
  5.     fixmenus()
  6.     
  7.     adjust the menus to reflect the status of windows, ie, if our
  8.     application window is frontmost, enable printing menu items,
  9.     disable Undo,Cut,Paste,Clear, and enable Copy if the front
  10.     window is not the clipboard window.
  11.     
  12.     if front window is _not_ our window, disable print items, and
  13.     enable _all_ of the edit menu items (in case the front window
  14.     is a Desk Accessory)
  15.     
  16. ====================================================================*/    
  17. fixmenus()
  18. {
  19.     if ((w_index = ourwindow(FrontWindow())) >= 0){
  20.         EnableItem(FileMenu,PageSetupItem);
  21.         EnableItem(FileMenu,PrintItem);
  22.         DisableItem(EditMenu,UndoItem);
  23.         DisableItem(EditMenu,CutItem);
  24.         DisableItem(EditMenu,PasteItem);
  25.         DisableItem(EditMenu,ClearItem);
  26.         if (FrontWindow() == clip_window)
  27.             DisableItem(EditMenu,CopyItem);
  28.         else
  29.             EnableItem(EditMenu,CopyItem);
  30.     }
  31.     else{
  32.         DisableItem(FileMenu,PageSetupItem);
  33.         DisableItem(FileMenu,PrintItem);
  34.         EnableItem(EditMenu,UndoItem);
  35.         EnableItem(EditMenu,CutItem);
  36.         EnableItem(EditMenu,PasteItem);
  37.         EnableItem(EditMenu,ClearItem);
  38.         EnableItem(EditMenu,CopyItem);
  39.     }
  40. }
  41.  
  42. /*====================================================================
  43.  
  44.     makemenus()
  45.     
  46.     initialize and install the Apple, File, and Edit menus from the
  47.     resource fork of the application.  Install Desk Accessories 
  48.     (DRVRs) into the Apple menu
  49.     
  50. ====================================================================*/    
  51. makemenus()
  52. {
  53.     AddResMenu(AppleMenu= GetMenu(AppleID),(ResType)'DRVR');
  54.     SetItem(AppleMenu,1,"\pAbout LightspeedC Shell");
  55.     InsertMenu(AppleMenu,0);
  56.  
  57.     InsertMenu(FileMenu= GetMenu(FileID),0);
  58.  
  59.     InsertMenu(EditMenu= GetMenu(EditID),0);
  60.  
  61.     DrawMenuBar();
  62. }
  63.  
  64. /*====================================================================
  65.  
  66.     doapplemenu(int)
  67.     
  68.     do About... stuff if the menu item is 1, otherwise open a desk
  69.     accessory selected from the Apple Menu
  70.     
  71. ====================================================================*/    
  72. doapplemenu(menuitem)
  73. int            menuitem;
  74. {
  75.     Str255            accName;
  76.  
  77.     switch(menuitem){
  78.         case AboutItem:        doabout("LightspeedC Shell","07.27.88");
  79.                             break;
  80.  
  81.         default:            GetItem(AppleMenu,menuitem,accName);
  82.                             OpenDeskAcc(accName);
  83.                             break;
  84.     }
  85. }
  86.  
  87. /*====================================================================
  88.  
  89.     dofilemenu(int)
  90.     
  91.     dispatch to routines selected from the File menu.  An alert
  92.     indicating a routine is not implemented is included for the
  93.     items that are not yet implemented.
  94.     
  95. ====================================================================*/    
  96. dofilemenu(menuitem)
  97. int            menuitem;
  98. {
  99.     switch(menuitem){
  100.         case NewItem:            noimplementation();
  101.                                 break;
  102.  
  103.         case OpenItem:            noimplementation();
  104.                                 break;
  105.  
  106.         case CloseItem:            noimplementation();
  107.                                 break;
  108.  
  109.         case SaveItem:            noimplementation();
  110.                                 break;
  111.  
  112.         case SaveAsItem:        noimplementation();
  113.                                 break;
  114.  
  115.         case PageSetupItem:        dopagesetup();
  116.                                 break;
  117.  
  118.         case PrintItem:            print_it();
  119.                                 break;
  120.  
  121.         case QuitItem:            quitting = TRUE;
  122.                                 break;
  123.  
  124.         default:                break;
  125.     }
  126. }
  127.  
  128. /*====================================================================
  129.  
  130.     doeditmenu(int)
  131.     
  132.     if the Show/Hide clipboard item is selected, branch to routine
  133.     that toggles is visibility.
  134.     
  135.     otherwise, if the Edit menu item is not intended for a
  136.     Desk Accessory, (SystemEdit(item-1) == FALSE), then it
  137.     is ours to handle.  After using an Edit menu item, branch
  138.     to "changedscrap()" to update the clipboard contents
  139.     
  140. ====================================================================*/    
  141. doeditmenu(menuitem)
  142. int        menuitem;
  143. {
  144.     if (menuitem==ClipItem)
  145.         showclipwindow();
  146.     else
  147.         if (!SystemEdit(menuitem-1)){
  148.             switch(menuitem){
  149.                 case UndoItem:        break;
  150.                 case CutItem:        break;
  151.                 case CopyItem:        break;
  152.                 case PasteItem:        break;
  153.                 case ClearItem:        break;
  154.                 default:            break;
  155.             }
  156.             changedscrap();
  157.         }
  158.         else{
  159.             changedscrap();
  160.         }
  161. }
  162.  
  163. /*====================================================================
  164.  
  165.     domenu(long)
  166.     
  167.     the long contains the Menu ID in the HiWord, and the Menu Item
  168.     in the LoWord.  Extract these, and dispatch to the individual
  169.     menu handling routines, passing to them the menu item selected
  170.     from their menu
  171.     
  172. ====================================================================*/    
  173. domenu(mChoice)
  174. long        mChoice;
  175. {
  176.     int            MenuID,MenuItem;
  177.  
  178.     MenuID = HiWord(mChoice);
  179.     MenuItem = LoWord(mChoice);
  180.  
  181.     switch (MenuID){
  182.         case AppleID:    doapplemenu(MenuItem);
  183.                         break;
  184.  
  185.         case FileID:    dofilemenu(MenuItem);
  186.                         break;
  187.  
  188.         case EditID:    doeditmenu(MenuItem);
  189.                         break;
  190.  
  191.         default:        break;
  192.  
  193.     }
  194.     HiliteMenu(0);
  195. }
  196.  
  197.